home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1988 December
/
Ahoy_Magazine_88-12_1988_Double_L.d64
/
Floating Point
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
2KB
|
49 lines
1 rem===================================
2 rem
3 rem floating point converter
4 rem rupert report #60
5 rem
6 rem===================================
10 print"[147]floating point converter"
15 print "========================"
20 x0=sqr(36) :rem: x0 must be first variable
30 sp$=" "+chr$(13)
40 def fnptr(m)=peek(m)+256*peek(m+1)
60 false=0: true=not false: c64=false
70 if fre(0)=fre(1) then c64=true
80 vp=47: if c64 then vp=45 :rem start variables pointer
90 sv=fnptr(vp) :rem start variables
100 s1=sv+2: s2=sv+3: s3=sv+4: s4=sv+5: s5=sv+6 :rem storage area for x0
110 if not c64 then (NULL) 1
200 rem ========= fp to stored values ==
210 print "(x to switch modes; q to quit)"
220 print "enter floating pt. value :"
225 input x$: if x$="" then 260
230 if x$="q" then end
240 if x$="x" then print "[145][145][145]";sp$;sp$;"[145][145][145]": goto 310
250 x0=val(x$)
260 v1=peek(s1): v2=peek(s2): v3=peek(s3): v4=peek(s4): v5=peek(s5)
270 gosub 1010
280 goto 210
300 rem ========= stored values to fp ==
310 print: print "(x to switch modes; q to quit)"
320 print "enter 5 stored values (0 to 255) : "
330 input "first value";x1$: v1=val(x1$)
340 if x1$="x" then print "[145][145][145]";sp$;sp$;sp$;"[145][145][145][145]": goto 210
350 if x1$="q" then end
360 input "2nd value";x2$: v2=val(x2$)
370 input "3rd value";x3$: v3=val(x3$)
380 input "4th value";x4$: v4=val(x4$)
390 input "5th value";x5$: v5=val(x5$)
400 poke s1,v1: poke s2,v2: poke s3,v3: poke s4,v4: poke s5,v5
410 gosub 1010
420 goto 310
1000 rem ===== conversion & output =====
1010 print v1; v2; v3; v4; v5
1020 rem -- exponent, mantissa, sign --
1030 ex=v1-128
1040 mn=(((v5/256+v4)/256+v3)/256 + (128 or v2))/256
1050 sn=1: if v2 >= 128 then sn=-1
1060 print ""; sn*mn; "[146]* 2^"; ex; "[146] = "; x0; "[146]": print
1070 return